"""
@title(TenX腾晓2024年12月考核答题文件)
@warning(请勿修改参数和返回值)
@warning(请认真填写__init__中的数据)
@author(1323230180)
@license(CC BY-SA 4.0 License)
"""
import os
from copy import deepcopy


class TenXClass:
    def __init__(self):
        # 获取当前文件名并截取文件名的学号-姓名
        file_name = os.path.basename(__file__).split('.')[0].split("-")
        self.id = file_name[0]  # 学号
        self.name = file_name[1]  # 姓名

    @staticmethod
    def question1(*args) -> list[str]:
        binary_tree = deepcopy(args[0]) # 传入的地牢结构（二叉树）
        record = [] # 初始路径记录
        result = [] # 最终答案路径
        max_depth = 0 # 记录最大深度

        def develop(root, depth):
            nonlocal record, result, max_depth

            if not root:
                return

            record.append(root.value)

            if not root.left and not root.right:
                if root.value == 0:
                    if depth > max_depth:# 发现更深的路径，更新最大深度并重置结果                    
                        max_depth = depth
                        result = [list(record)]
                    elif depth == max_depth:# 深度相同，添加到结果中                    
                        result.append(list(record))
                record.pop() #回溯
                return
       
            develop(root.left, depth + 1)
            develop(root.right, depth + 1)
        
            record.pop()

        develop(binary_tree.root, 1)
        result_final = [''.join(map(str, sub_list)) for sub_list in result]# 将路径转换为字符串

        return result_final

    @staticmethod
    def question2(*args) -> str:
        matrix = deepcopy(args[0])  # 传入的河流结构（矩阵）
        max_row = len(matrix)
        count_list = []
        for i in range(max_row):
            count_list.append(max(matrix[i]))
        result = ''.join(map(str,count_list))

        return result

    @staticmethod
    def question3(*args) -> int:
        total_num = 6*pow(7,999)
        delete_num = 5*pow(6,999)
        result = (total_num - delete_num)%99999999    
        return result

    @staticmethod
    def question4(*args) -> int:
        n = deepcopy(args[0])  # 用于搭建金字塔的球个数
        add_num = 1
        subtraction_num = 1
        layer = 0
        result = n - 1
        while result >= 0:
            layer += 1 
            add_num += 1
            subtraction_num = subtraction_num + add_num
            result = result - subtraction_num
            
        return layer

    @staticmethod
    def question5(*args) -> list[str]:
        balls = deepcopy(args[0])  # 五行空间球的初始值
        while any(balls[i] < 10000 for i in range(5)):
            balls[0] = balls[3] + balls[4]
            if all(balls[i] >= 10000 for i in range(5)):
                break
            balls[1] = balls[4] + balls[0]
            if all(balls[i] >= 10000 for i in range(5)):
                break
            balls[2] = balls[0] + balls[1]
            if all(balls[i] >= 10000 for i in range(5)):
                break
            balls[3] = balls[1] + balls[2]
            if all(balls[i] >= 10000 for i in range(5)):
                break
            balls[4] = balls[2] + balls[3] 

        return list(map(str, balls))